<template>
  <div>
    <el-table :data="admins" border :stripe="true" style="width: 100%">
      <el-table-column prop="_id" label="管理员编号"> </el-table-column>
      <el-table-column prop="account" label="管理员账号"> </el-table-column>
      <el-table-column prop="name" label="管理员姓名"> </el-table-column>
      <el-table-column prop="permissions" label="管理员状态">
        <template slot-scope="scope">
          <el-button
            type="success"
            v-if="scope.row.permissions"
            @click="scope.row.permissions = !scope.row.permissions"
            >可操作</el-button
          >
          <el-button
            type="info"
            v-else
            @click="scope.row.permissions = !scope.row.permissions"
            >禁用</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="修改">
        <template slot-scope="scope">
          <el-button type="warning" @click="onsubmit(scope.row)"
            >修改</el-button
          >
          <!-- <router-link :to="''"></router-link> -->
        </template>
      </el-table-column>
      <el-table-column label="删除">
        <template slot-scope="scope">
          <el-button type="danger" @click="delAdmin(scope._id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions, mapState } = createNamespacedHelpers("admins");
export default {
  created() {
    this.getAdmins();
  },

  computed: {
    ...mapState(["admins"]),
  },
  methods: {
    ...mapActions(["getAdmins", "delAdmin", "updateAdmin"]),
    onsubmit(data) {
      console.log(data);
      localStorage.adminname = data.name;
      this.$router.push(`/adminsSystem/updateAdmin/${data._id}`);
    },
  },
};
</script>